package day1206zy.day1206zy10;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class demo10 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> clazz = Class.forName("day1206zy10.Student");
        Field name = clazz.getDeclaredField("name");
        Field age = clazz.getDeclaredField("age");
        Object o = clazz.getConstructor().newInstance();
        name.setAccessible(true);
        age.setAccessible(true);
        name.set(o,"小虎");
        age.set(o,25);
        Object o1 = name.get(o);
        Object o2 = age.get(o);
        System.out.println(o1);
        System.out.println(o2);
    }
}
